jQuery(function(){
	///新建投诉与建议
	jQuery('.addBtn').on('click',function(){
		window.location = window.rootPath+"/ui/aftersalereturnvisit/add";
	})
	//获取显示页面数据 服务器分页
	var serverData = {};
	var serverTable;


		serverTable = jQuery('#accessTable').DataTable({
			"serverSide": true,
			"ordering": false,
			"ajax": {
				"dataType": "json",
				"type": "get",
				"cache": false,
				"url":window.rootPath+ '/ui/aftersalereturnvisit/getpage',
				"data": function (d) {
					return $.extend({}, d, serverData);
				}
			},
			columns: [
				{
					data: null,
					defaultContent: ""//排序
				},
				{
					data: null,
					defaultContent: "",
					render: function (data, type, full, meta) {

						var id=data.id
						var operate ='<input type="checkbox" class="checkchild">';
						return operate;

					}
				},
				{
					data: 'revisitTime',
					render : function(data,
									  type, full,
									  meta) {
						if (data) {
							return moment(data).format("YYYY-MM-DD");
						}
					}
				},
				{
					data: 'registrant'
				},
				{
					data: 'managedcode'
				},
				{
					data: 'contractNumber',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 6) ? '<font title="'+data+'">'+data.substring(0,6)+'...'+'</font>' : data;
						}
					}
				},
				{
					data: 'customerUnit',
	                render:function(data,type,full,meta){
	                	if(data == null || data == undefined || data == ""){
							return data;
						}else{
							return (data.length > 10) ? '<font title="'+data+'">'+data.substring(0,10)+'...'+'</font>' : data;
						}
					}
				},
				{
					data: 'serviceType'
				},
				{
					data: 'servicer'
				},
				{
					data: 'assess'
				},
	            {
	                data: 'attachNumber',
	                 render: function (data, type, full, meta) {
	                 var dOut;
	                 if(data==null){
	                   dOut='<td class="center" ><span class="badge label-pill label-primary">'+0+'</span></td>'
	                 }else{
	                   dOut='<td class="center" ><span class="badge label-pill label-primary">'+data+'</span></td>'
	                 }
	                   return dOut;
	                 }
	                    
	                }  
				
			],
			"drawCallback": function (oSettings) {
				var k = 0;
				var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

				for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
					$('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
					k++;
				}

			}
		});
		//列表全选
		 $("#checkAll").click(function(){
			 	var check = $(this).prop("checked");
			     $(".checkchild").prop("checked", check);
				});

	////编辑客户
	jQuery('.editBtn').on('click', function () {
		var selects=getSelect("#accessTable",1);
		if(selects.length>1){
			$.springLemonDialog({
				content: '只能编辑一条投标的反馈',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		}
		else if(selects.length==0){
			$.springLemonDialog({
				content: '请选择要编辑的记录',// 确认文本
				clickButton: function (sender, modal, index) {// 按钮事件处理
					$(this).closeDialog(modal);
				}
			});
		}else if(selects.length==1){
			var id=selects[0].id;
			window.location = window.rootPath+"/ui/aftersalereturnvisit/edit"+"?id="+id;
		}
	});
	/////删除客户/////
	jQuery('.delBtn').on('click', function () {
		var selects=getSelect("#accessTable",1);
		var url=window.rootPath+"/ui/aftersalereturnvisit/del";
		delSelect(selects,url,serverTable)
	});
	//客户查询
	jQuery('.searchBtn').on('click', function() {
		serverData.key = jQuery('#keyword').val();
		serverTable.draw();
	})
	// 撤销客户查询
	jQuery('.cancelBtn').on("click", function() {
		jQuery('#keyword').val('');
		serverData.key = '';
		serverTable.draw();
	});
});
